home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / stringhashdemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-09  |  2.0 KB  |  66 lines

  1. {
  2. GPC demo program. How to hash strings using the StringUtils unit.
  3.  
  4. Copyright (C) 2000-2001 Free Software Foundation, Inc.
  5.  
  6. Author: Frank Heckenbach <frank@pascal.gnu.de>
  7.  
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, version 2.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; see the file COPYING. If not, write to
  19. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.
  21.  
  22. As a special exception, if you incorporate even large parts of the
  23. code of this demo program into another program with substantially
  24. different functionality, this does not cause the other program to
  25. be covered by the GNU General Public License. This exception does
  26. not however invalidate any other reasons why it might be covered
  27. by the GNU General Public License.
  28. }
  29.  
  30. program StringHashDemo;
  31.  
  32. uses GPC, StringUtils;
  33.  
  34. var
  35.   HashTable : PStrHashTable;
  36.   n : Integer;
  37.   s : TString;
  38.  
  39. begin
  40.   Writeln ('String hash demo');
  41.   Write ('Case sensitive? ');
  42.   Readln (s);
  43.   HashTable := NewStrHashTable (DefaultHashSize, (s <> '') and (LoCase (s [1]) = 'y'));
  44.   Writeln ('Enter some strings to store (empty string when finished).');
  45.   n := 0;
  46.   repeat
  47.     Inc (n);
  48.     Write ('#', n, ': ');
  49.     Readln (s);
  50.     if s <> '' then AddStrHashTable (HashTable, s, n, nil)
  51.   until s = '';
  52.   Writeln ('Now enter some strings to search (empty string when finished).');
  53.   repeat
  54.     Readln (s);
  55.     if s <> '' then
  56.       begin
  57.         n := SearchStrHashTable (HashTable, s, null);
  58.         if n = 0 then
  59.           Writeln ('String not found.')
  60.         else
  61.           Writeln ('String was entered at #', n)
  62.       end
  63.   until s = '';
  64.   DisposeStrHashTable (HashTable)
  65. end.
  66.